package thirdPartyUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;

import java.util.HashMap;


public class FastJsonDemo {
    public static void main(String[] args) {
        String json="[\n" +
                "  {\n" +
                "     \"studentName\":\"lily\",\n" +
                "     \"studentAge\":12\n" +
                "  },\n" +
                "  {\n" +
                "     \"studentName\":\"lucy\",\n" +
                "     \"studentAge\":15\n" +
                "  }\n" +
                "]";
        JSONArray jsonArray = JSON.parseArray(json);
        JSONObject jsonObject = (JSONObject)jsonArray.get(1);

        String studentName = jsonObject.getString("studentName");
        System.out.println(studentName);

        String s= "{\"dataListType\": \"dataListCu\"}";
        String s1 = JSON.toJSONString(s);
        String s2 = JSON.toJSONString(s1);
        System.out.println(s2);

        HashMap<String, String> map = new HashMap<>();


        Object read = JSONPath.eval(jsonArray, "$[*]");
        for (Object o : (JSONArray) read) {
            String s3 = ((JSONObject) o).getString("studentName") + "add";
            JSONPath.set(o,"studentName",s3);
        }
        System.out.println(jsonArray);

        read = JSONPath.eval(jsonArray, "$[?(@.studentAge < 14)]");


        String complexJson = "{\n" +
                "            \"operType\": \"I\",\n" +
                "            \"reqNo\": \"I\",\n" +
                "            \"topGroupList\": [\n" +
                "                {\n" +
                "                    \"groupNature\": \"3\", \n" +
                "                    \"groupName\": \"总集团对账组4\",\n" +
                "                    \"industryCategory\": \"1\", \n" +
                "                    \"groupLevel\": \"1\", \n" +
                "                    \"provinceBranch\": \"0001\",\n" +
                "                    \"creater\": \"1\",\n" +
                "                    \"tel\": \"15999888991\",\n" +
                "                    \"operatorBranch\": \"0001\", \n" +
                "                    \"contactDept\": \"联系部门\",\n" +
                "                    \"groupBriefName\": \"集团简称\", \n" +
                "                    \"groupZipcode\": \"20000\", \n" +
                "                    \"contactPerson\": \"联系人\",\n" +
                "                    \"address\": \"联系人地址\",\n" +
                "                    \"email\": \"邮箱\",\n" +
                "                    \"contactFax\": \"\",\n" +
                "                    \"contactPhone\": \"18323472341\",\n" +
                "                    \"lastModifier\": \"最后修改人\",\n" +
                "                    \"remark\": \"备注\",\n" +
                "                    \"merchantList\": [{\n" +
                "                            \"branch\": \"101500\",\n" +
                "                            \"customerId\": \"949f834c66b24603ad931e53941405f2\",\n" +
                "                            \"merchantNo\": \"QRC480224106523\",\n" +
                "\t\t\t\t\t\t\t\"result\":\"success\"\n" +
                "                    },{\n" +
                "                        \"branch\": \"101300\",\n" +
                "                        \"customerId\": \"B360AE98FB6920DsE043AC10030720DA\",\n" +
                "                        \"merchantNo\": \"U687263419UMS\"\n" +
                "                    }],\n" +
                "                    \"subGroupList\": [\n" +
                "                        {\n" +
                "                        \"groupNature\": \"3\",\n" +
                "                        \"groupName\": \"子集团名称\",\n" +
                "                        \"groupBriefName\": \"集团简称\",\n" +
                "                        \"provinceBranch\": \"0001\",\n" +
                "                        \"tel\": \"15999999992\",\n" +
                "                        \"operatorBranch\": \"0001\",\n" +
                "                        \"contactDept\": \"联系部门\",\n" +
                "                        \"groupZipcode\": \"100000\",\n" +
                "                        \"contactPerson\": \"联系人\",\n" +
                "                        \"address\": \"联系人地址\",\n" +
                "                        \"email\": \"邮箱\",\n" +
                "                        \"contactFax\": \"\",\n" +
                "                        \"contactPhone\": \"18323472341\",\n" +
                "                        \"lastModifier\": \"最后修改人\",\n" +
                "                        \"remark\": \"子级集团信息录入\",\n" +
                "                        \"subGroupMerchantList\": [{\n" +
                "                            \"branch\": \"101500\",\n" +
                "                            \"customerId\": \"949f834c66b24603ad931e53941405f2\",\n" +
                "                            \"merchantNo\": \"QRC480224106523\",\n" +
                "\t\t\t\t\t\t\t\"result\":\"success\"\n" +
                "                        },{\n" +
                "                            \"branch\": \"101300\",\n" +
                "                            \"customerId\": \"B360AE98FB6920DsE043AC10030720DA\",\n" +
                "                            \"merchantNo\": \"U687263419UMS\"\n" +
                "                        }]\n" +
                "                        }\n" +
                "                    ]\n" +
                "                }\n" +
                "            ]}   ";
        JSONObject c = JSON.parseObject(complexJson);
        read = JSONPath.eval(c, "$..groupMerchantList[?(@.result=='success')]");
//        read = JSONPath.eval(c, "$..groupMerchantList[?(@.result=='sucddcess')]");
        for (Object o : (JSONArray) read) {
            ((JSONObject)o).put("add","addValue");
//            System.out.println(read);
        }
        System.out.println(c);



        String test21="{\n" +
                "\t\t\t\t\"bizType\":[\n" +
                "\t\t\t\t\t\"1\",\n" +
                "\t\t\t\t\t\"2\"\n" +
                "\t\t\t\t],\n" +
                "\t\t\t\t\"channel\":\"2\",\n" +
                "\t\t\t\t\"groupNature\":[\n" +
                "\t\t\t\t\t\"2\"\n" +
                "\t\t\t\t],\n" +
                "\t\t\t\t\"groupList\":{\n" +
                "\t\t\t\t\t\"isContainTop\":\"1\",\n" +
                "\t\t\t\t\t\"topGroupList\":[\n" +
                "\t\t\t\t\t\t{\n" +
                "\t\t\t\t\t\t\t\"address\":\"\",\n" +
                "\t\t\t\t\t\t\t\"provinceBranch\":\"0001\",\n" +
                "\t\t\t\t\t\t\t\"groupNature\":\"2\",\n" +
                "\t\t\t\t\t\t\t\"contactPerson\":\"中海地产\",\n" +
                "\t\t\t\t\t\t\t\"contactDept\":\"中海地产\",\n" +
                "\t\t\t\t\t\t\t\"result\":\"总集团保存失败：顶级集团名称：中海地产该机构下已存在相同集团性质、相同集团名称的总对账组！！\",\n" +
                "\t\t\t\t\t\t\t\"groupBriefName\":\"中海地产\",\n" +
                "\t\t\t\t\t\t\t\"groupName\":\"中海地产\",\n" +
                "\t\t\t\t\t\t\t\"operatorBranch\":\"0001\",\n" +
                "\t\t\t\t\t\t\t\"tel\":\"中海地产\",\n" +
                "\t\t\t\t\t\t\t\"groupLevel\":1,\n" +
                "\t\t\t\t\t\t\t\"contactPhone\":\"中海地产\",\n" +
                "\t\t\t\t\t\t\t\"merchantList\":[\n" +
                "\t\t\t\t\t\t\t\t{\n" +
                "\t\t\t\t\t\t\t\t\t\"result\":\"false,未处理到\",\n" +
                "\t\t\t\t\t\t\t\t\t\"stmtSeal\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respDesc\":\"查询商户信息异常\",\n" +
                "\t\t\t\t\t\t\t\t\t\"appTypeId\":\"68\",\n" +
                "\t\t\t\t\t\t\t\t\t\"mchntId\":\"5b613ae9b5e144788ef4b5acbdfcbb4b\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideStmt\":\"0\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideAcctService\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"branch\":\"103700\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respCode\":\"06900023\",\n" +
                "\t\t\t\t\t\t\t\t\t\"merchantNo\":\"000540115200118\"\n" +
                "\t\t\t\t\t\t\t\t},\n" +
                "\t\t\t\t\t\t\t\t{\n" +
                "\t\t\t\t\t\t\t\t\t\"result\":\"false,未处理到\",\n" +
                "\t\t\t\t\t\t\t\t\t\"stmtSeal\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respDesc\":\"查询商户信息异常\",\n" +
                "\t\t\t\t\t\t\t\t\t\"appTypeId\":\"40\",\n" +
                "\t\t\t\t\t\t\t\t\t\"mchntId\":\"867da09c92534d0c87ed9680177f5dce\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideStmt\":\"0\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideAcctService\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"branch\":\"103700\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respCode\":\"06900023\",\n" +
                "\t\t\t\t\t\t\t\t\t\"merchantNo\":\"000540115200126\"\n" +
                "\t\t\t\t\t\t\t\t},\n" +
                "\t\t\t\t\t\t\t\t{\n" +
                "\t\t\t\t\t\t\t\t\t\"result\":\"false,未处理到\",\n" +
                "\t\t\t\t\t\t\t\t\t\"stmtSeal\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respDesc\":\"查询商户信息异常\",\n" +
                "\t\t\t\t\t\t\t\t\t\"appTypeId\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"mchntId\":\"66d4f8d2fdcd4f1bbdc72d5940d48391\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideStmt\":\"0\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideAcctService\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"branch\":\"101100\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respCode\":\"06900023\",\n" +
                "\t\t\t\t\t\t\t\t\t\"merchantNo\":\"000610359980155\"\n" +
                "\t\t\t\t\t\t\t\t},\n" +
                "\t\t\t\t\t\t\t\t{\n" +
                "\t\t\t\t\t\t\t\t\t\"result\":\"false,未处理到\",\n" +
                "\t\t\t\t\t\t\t\t\t\"stmtSeal\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respDesc\":\"查询商户信息异常\",\n" +
                "\t\t\t\t\t\t\t\t\t\"appTypeId\":\"40\",\n" +
                "\t\t\t\t\t\t\t\t\t\"mchntId\":\"7603c1effc47488c8127478ed2056282\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideStmt\":\"0\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideAcctService\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"branch\":\"101100\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respCode\":\"06900023\",\n" +
                "\t\t\t\t\t\t\t\t\t\"merchantNo\":\"000610359980201\"\n" +
                "\t\t\t\t\t\t\t\t},\n" +
                "\t\t\t\t\t\t\t\t{\n" +
                "\t\t\t\t\t\t\t\t\t\"result\":\"false,未处理到\",\n" +
                "\t\t\t\t\t\t\t\t\t\"stmtSeal\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respDesc\":\"查询商户信息异常\",\n" +
                "\t\t\t\t\t\t\t\t\t\"appTypeId\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"mchntId\":\"e91e1e44921c4c5a9de92383b2e87bd3\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideStmt\":\"0\",\n" +
                "\t\t\t\t\t\t\t\t\t\"provideAcctService\":\"1\",\n" +
                "\t\t\t\t\t\t\t\t\t\"branch\":\"102100\",\n" +
                "\t\t\t\t\t\t\t\t\t\"respCode\":\"06900023\",\n" +
                "\t\t\t\t\t\t\t\t\t\"merchantNo\":\"000426115200147\"\n" +
                "\t\t\t\t\t\t\t\t}\n" +
                "\t\t\t\t\t\t\t],\n" +
                "\t\t\t\t\t\t\t\"groupCode\":\"\"\n" +
                "\t\t\t\t\t\t}\n" +
                "\t\t\t\t\t],\n" +
                "\t\t\t\t\t\"operType\":\"I\"\n" +
                "\t\t\t\t},\n" +
                "\t\t\t\t\"attachList\":[\n" +
                "\t\t\t\t\t{\n" +
                "\t\t\t\t\t\t\"msg\":\"success\",\n" +
                "\t\t\t\t\t\t\"fileName\":\"商户集团关联模板.xlsx\",\n" +
                "\t\t\t\t\t\t\"code\":\"0\",\n" +
                "\t\t\t\t\t\t\"fileSize\":15810,\n" +
                "\t\t\t\t\t\t\"name\":\"商户集团关联模板.xlsx\",\n" +
                "\t\t\t\t\t\t\"fileKey\":\"ubop/bosAttach/99a977668a93492480dc207db7301655\"\n" +
                "\t\t\t\t\t}\n" +
                "\t\t\t\t],\n" +
                "\t\t\t\t\"priority\":\"普通\",\n" +
                "\t\t\t\t\"merchantName\":\"中海地产\",\n" +
                "\t\t\t\t\"requireStatement\":\"中海地产\",\n" +
                "\t\t\t\t\"processNo\":\"UP20230518000008\",\n" +
                "\t\t\t\t\"instId\":\"0\",\n" +
                "\t\t\t\t\"instIdName\":\"银联商务股份有限公司\",\n" +
                "\t\t\t\t\"processName\":\"张河星的中海地产\",\n" +
                "\t\t\t\t\"dealNote\":\"\",\n" +
                "\t\t\t\t\"groupLevel\":[\n" +
                "\t\t\t\t\t\"1\"\n" +
                "\t\t\t\t]\n" +
                "\t\t\t}";
        read = JSONPath.eval(test21, "$.groupList.topGroupList[*].tel");
        System.out.println(read);
    }
}

class Student{
    String studentName;

}